package cn.hss.io.convert;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

/**OutputStreamWriter转换流
 * 将字符转换为字节
 * @author 作者：HeShaoShuai
 * @Email 邮箱：2569819541@qq.com
 * @Date 日期：2023/4/26 15:49
 * @Package 包名：cn.hss.io.convert
 * @Project 项目名：JavaSE
 * @Version 1.0
 */
public class ConvertStreamWriterTest {
	public static void main(String[] args) {
		try {
			//创建转换流对象，不指定字符集，默认是UTF-8
			OutputStreamWriter osw = new OutputStreamWriter(
					new FileOutputStream("out.txt"));
			osw.write("犯我中华者，虽远必诛");
			osw.close();
			//创建转换流对象，指定编码格式GBK,中文出现乱码
			OutputStreamWriter osw2 = new OutputStreamWriter(
					new FileOutputStream("out2.txt"),"GBK");
			osw2.write("你好，陕财职院");
			osw2.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
